package logic

import (
	"context"
	"debugservice/yqsl/internal/dooption"
	"debugservice/yqsl/internal/svc"
	"debugservice/yqsl/internal/types"
	"gitee.com/jmdvirus/jkgo/jk/jklog"

	"github.com/tal-tech/go-zero/core/logx"
)

type DebugRemoteCloseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDebugRemoteCloseLogic(ctx context.Context, svcCtx *svc.ServiceContext) DebugRemoteCloseLogic {
	return DebugRemoteCloseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DebugRemoteCloseLogic) DebugRemoteClose(req types.RequestSimple) (*types.ResponseCommand, error) {
	jklog.L().Debugln("req ", req.Id)
	s, err := dooption.DebugControlGlobal().DebugControlRemoteClose(req.Id)
	rc := &types.ResponseCommand{}
	rc.Id = req.Id
	if err != nil {
		rc.Code = 408
	} else {
		rc.Code = 200
	}
	rc.Result = s
	if len(s) == 0 {
		if err != nil {
			rc.Result = err.Error()
		} else {
			rc.Result = "no result"
		}
	}
	return rc, nil
}
